Login.vue<script setup>

import {
  CaretBottom,
  Promotion,
  SwitchButton,
} from '@element-plus/icons-vue'
import {ElMessage, ElMessageBox} from "element-plus";
import {useRouter} from "vue-router";
import {useUserInfoStore} from "@/stores/userInfo.js";
import {userInfo} from "@/api/user.js";

const userInfoStore = useUserInfoStore();
const getUserInfo = ()=>{
  userInfo ().then(res=>{
    userInfoStore.setUserInfo(res.data)
  })
}
getUserInfo()

const router = useRouter();
const logOut = () => {
  ElMessageBox.confirm(
      '你确认要退出吗？',
      '温馨提示',
      {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }
  ).then(
      async () => {
        // clear data in pinia
        userInfoStore.removeUserInfo()
        ElMessage.success("退出成功")
        await router.push('/login')
      }
  )
}
</script>

<template>
  <el-container class="layout-container">
    <!-- 左侧菜单 -->
    <el-aside width="200px">
      <div></div>
      <el-menu active-text-color="#ffd04b" background-color="#232323" text-color="#fff"
               router>
        <el-menu-item index="/admin/userManagement">
          <el-icon>
            <Promotion/>
          </el-icon>
          <span>用户管理</span>
        </el-menu-item>
        <el-menu-item index="/admin/roomManagement">
          <el-icon>
            <Promotion/>
          </el-icon>
          <span>客房管理</span>
        </el-menu-item>
        <el-menu-item index="/admin/drinksManagement">
          <el-icon>
            <Promotion/>
          </el-icon>
          <span>酒水管理</span>
        </el-menu-item>
        <el-menu-item index="/admin/employeeManagement">
          <el-icon>
            <Promotion/>
          </el-icon>
          <span>员工管理</span>
        </el-menu-item>
        <el-menu-item index="/admin/orderManagement">
          <el-icon>
            <Promotion/>
          </el-icon>
          <span>订单管理</span>
        </el-menu-item>
        <el-menu-item index="/admin/memberManagement">
          <el-icon>
            <Promotion/>
          </el-icon>
          <span>会员管理</span>
        </el-menu-item>
        <el-menu-item index="/admin/checkinManagement">
          <el-icon>
            <Promotion/>
          </el-icon>
          <span>入住管理</span>
        </el-menu-item>
        <el-menu-item index="/admin/count">
          <el-icon>
            <Promotion/>
          </el-icon>
          <span>统计报表</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    <!-- 右侧主区域 -->
    <el-container>
      <!-- 头部区域 -->
      <el-header>
        <div>欢迎：<strong>管理员</strong>{{ userInfoStore.userInfo.name }}</div>
        <el-button @click="logOut" :icon="SwitchButton">退出登录</el-button>
      </el-header>
      <!-- 中间区域 -->
      <el-main>
        <router-view/>
      </el-main>
      <!-- 底部区域 -->
      <el-footer>酒店预约管理系统</el-footer>
    </el-container>
  </el-container>
</template>

<style lang="scss" scoped>
.layout-container {
  height: 100vh;

  .el-aside {
    background-color: #232323;

    &__logo {
      height: 120px;
      background: url('@/assets/vue.svg') no-repeat center / 120px auto;
    }

    .el-menu {
      border-right: none;
    }
  }

  .el-header {
    background-color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;

    .el-dropdown__box {
      display: flex;
      align-items: center;

      .el-icon {
        color: #999;
        margin-left: 10px;
      }

      &:active,
      &:focus {
        outline: none;
      }
    }
  }

  .el-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #666;
  }
}
</style>
